package com.xpec.cipher.tals.record;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;

import com.xpec.cipher.tals.TalsConstance;

public abstract class HandShakeRecord extends TalsRecord
{
	@Override
	protected byte getContentType()
	{
		return TalsConstance.CONTENT_TYPE_HAND_SHAKE;
	}
	
	@Override
	protected int getContentLength()
	{
		return TalsConstance.BYTE_SIZE + getContentLengthWithoutHandShakeTypeSize();
	}

	@Override
	protected ChannelBuffer resolveSubStruct()
	{
		ChannelBuffer buffer = ChannelBuffers.buffer(getContentLength());
		buffer.writeByte(getHandShakeType());
		buffer.writeBytes(resolveSubStructWithoutHandShakeType());
		return buffer;
	}

	protected abstract byte getHandShakeType();

	protected abstract int getContentLengthWithoutHandShakeTypeSize();

	protected abstract byte[] resolveSubStructWithoutHandShakeType();

}
